'use strict';
const db = uniCloud.database()
const dbCmd = db.command
const ACTION = ['getUserTimes']
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const {
		action
	} = event
	let res = {}
	
	/**
	 * 获取用户使用次数
	 */
	const getUserTimes = async () => {
		const userTimeInfo = await db.collection('uni-id-users').where({username:event.username})
		.field({
			use_times:true,username:true,student_name:true
		})
		.limit(1).get()
		return userTimeInfo
	}
	
	
	switch (action) {
		case "getUserTimes":
			res = await getUserTimes()
			break;
		default:
			break;
	}
	//返回数据给客户端
	return res
};
